package cn.micai.base.lambda;

import java.util.stream.IntStream;
import java.util.stream.LongStream;

/**
 * 描述：Java – Check if Array contains a certain value?
 * <p>
 *
 * @author: 赵新国
 * @date: 2018/6/22 20:06
 */
public class PrimitiveArrayExample1 {

    public static void main(String [] args) {

        int[] number = {1,2,3,4,5,6,7,8,9};

        /*if (contains(number, 2)) {
            System.out.println("Hello 2");
        }*/

        // Java 8
        boolean result = IntStream.of(number).anyMatch(x -> x == 3);
        if (result) {
            System.out.println("Hello 3");
        } else {
            System.out.println("Where is number 3?");
        }

        long[] longs = {1,2,3,4,5,6,7,8,9};
        boolean result2 = LongStream.of(longs).anyMatch(x -> x == 4);
        if (result2) {
            System.out.println("Hello 4");
        } else {
            System.out.println("Where is number 4?");
        }

    }

    public static boolean contains(final int[] array, final int v) {
        boolean result = false;
        for (int i : array) {
            if (i == v) {
                result = true;
                break;
            }
        }
        return result;
    }
}
